package com.ipet.modules.sys.service.impl;

import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ipet.common.utils.PageUtils;
import com.ipet.common.utils.Query;

import com.ipet.modules.sys.dao.RegistrationDao;
import com.ipet.modules.sys.entity.RegistrationEntity;
import com.ipet.modules.sys.service.RegistrationService;


@Service("registrationService")
public class RegistrationServiceImpl extends ServiceImpl<RegistrationDao, RegistrationEntity> implements RegistrationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<RegistrationEntity> page = this.selectPage(
                new Query<RegistrationEntity>(params).getPage(),
                new EntityWrapper<RegistrationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public boolean add(RegistrationEntity registrationEntity) {
        Integer registrNo = 1;
        if(baseMapper.getLastNo() != null){
            registrNo = baseMapper.getLastNo() + 1;
        }
        registrationEntity.setCreateTime(new Date());
        registrationEntity.setRegistrNo(registrNo);
        return insert(registrationEntity);
    }

}
